import axios, { AxiosInstance } from 'axios'

import appEnvironment from '@/app-environments'
import { getToken  } from '@/utils'

const {
    networkHosts: {
        apiServer1: {
            fullHost,
        },
    },
} = appEnvironment

const fileClient: AxiosInstance = axios.create({
    baseURL: fullHost,
    responseType: 'blob',
    timeout: 2 * 60 * 1000, // 2 分钟
})

fileClient.interceptors.request.use((config) => {
    const { headers } = config
    const token = getToken()

    if(token) {
        config.headers['Authorization'] = 'Bearer ' + token
    }
    delete headers.shouldNotUseAuthToken

    return config
})

export default fileClient
